package org.answer.controller;

import org.answer.constant.MessageConstant;
import org.answer.entity.Result;
import org.answer.pojo.AddressMap;
import org.answer.service.AddressService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address")
public class MobilAddressController {

    @Reference
    private AddressService addressService;

    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<AddressMap> addressMaps = addressService.findAll();
            return new Result(true,MessageConstant.GET_ADDRESS_SUCCESS,addressMaps);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_ADDRESS_FALL);
        }
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            AddressMap addressMap = addressService.findById(id);
            return new Result(true,MessageConstant.GET_ADDRESS_SUCCESS,addressMap);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_ADDRESS_FALL);
        }
    }

}
